package com.ttc.ssm.service.admin.impl;

import com.ttc.ssm.common.CompanyPage;
import com.ttc.ssm.mapper.admin.AdMapper;
import com.ttc.ssm.po.Ad;
import com.ttc.ssm.service.admin.AdService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by 58296 on 2016/8/1.
 */
public class AdServiceImpl implements AdService {
    @Autowired
    AdMapper adMapper;
    @Override
    public List<Ad> selectAdForPage(CompanyPage companyPage) throws Exception {
        return adMapper.selectAdForPage(companyPage);
    }

    @Override
    public int countRows(CompanyPage companyPage) throws Exception {
        return adMapper.countRows(companyPage);
    }

    @Override
    public void deleteAds(Map<String, Object> map) throws Exception {
        adMapper.deleteAds(map);
    }

    @Override
    public void updateAd(Ad ad) throws Exception {
        ad.setDate_modified(new Date());
        adMapper.updateAd(ad);
    }

    @Override
    public void insertAd(Ad ad) throws Exception {
        Date d = new Date();
        ad.setDate_added(d);
        adMapper.insertAd(ad);
    }

    @Override
    public void updateAdStatus(int ad_id, int status) throws Exception {
        Date d = new Date();
        String s;
        java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        s = format1.format(d);
        System.out.println("=====================>"+s);
        adMapper.updateAdStatus(ad_id,status,s);
    }

    @Override
    public Ad selectAdById(int ad_id) throws Exception {
        return adMapper.selectAdById(ad_id);
    }
}
